<template>
	<div class="apply_frozen_wrapper">
		<div class="form">
			<h4>是否冻结账号</h4>
			<el-switch v-model="valiRule" active-value="1" inactive-value="2" @change="updateFrozenConfig()"></el-switch>
		</div>
		<div class="tips">开启之后，输入几次错误后会进行登录锁定</div>
		<div class="set" v-if="valiRule === '1'">
			<sw-custom-input size="mini" type="number" v-model="frozenData.errorTimeLen" />
			<font>秒钟内，</font>
			<span>账号连续输错超过</span>
			<sw-custom-input size="mini" type="number" v-model="frozenData.errorCount1" />
			<font>次，出现验证码，</font>
			<span>账号连续输错超过</span>
			<sw-custom-input size="mini" type="number" v-model="frozenData.errorCount" />
			<font>次，</font>
			<span>锁定账号</span>
			<sw-custom-input size="mini" type="number" v-model="frozenData.frozenLen" />
			<font>秒钟</font>
			<el-button size="mini" type="primary" @click="updateFrozenConfig()">保存</el-button>
		</div>
	</div>
</template>

<script>
import { mapGetters } from 'vuex';
import { updateFrozenSetting } from '@/api/system/tbSysSite';
export default {
	data() {
		return {
			valiRule: '',
			frozenData: {}
		};
	},
	computed: {
		...mapGetters(['siteInfo'])
	},
	mounted() {
		this.valiRule = this.siteInfo.valiRule;
		this.frozenData = {
			frozenLen: this.siteInfo.frozenLen,
			errorCount: this.siteInfo.errorCount,
			errorCount1: this.siteInfo.errorCount1,
			errorTimeLen: this.siteInfo.errorTimeLen
		};
	},
	methods: {
		//更新锁定设置
		async updateFrozenConfig() {
			let params = { id: this.siteInfo.id, ...this.frozenData, valiRule: this.valiRule };
			let result = await updateFrozenSetting(params).then((res) => res.data);
			if (result.code === '0') {
				this.$message.success('修改冻结设置成功');
				this.$store.dispatch('getSiteBaseInfo');
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.apply_frozen_wrapper {
	display: flex;
	flex-direction: column;
	flex: 1;
	padding: 16px;
	overflow: hidden;

	.form {
		display: flex;
		align-items: center;

		h4 {
			margin-right: 10px;
			line-height: 1;
		}
	}

	.tips {
		font-size: 14px;
		line-height: 1;
		color: #909399;
		margin-top: 10px;
	}

	.set {
		display: flex;
		align-items: center;
		margin-top: 12px;

		span {
			margin-right: 10px;
		}

		font {
			margin-left: 10px;
		}

		.el-input__inner {
			padding: 0 10px;
		}

		.el-input {
			width: 60px;
			font-size: 14px;
			text-align: center;
		}

		.el-button {
			margin-left: 10px;
		}
	}
}
</style>
